//
//  ColumnsViewController.m
//  SYiDaiy
//
//  Created by dllo on 16/9/2.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ColumnsViewController.h"
#import "TAMacro.h"
#import "FiveColumnsTableViewCell.h"
#import "FiveColumnsDetailViewController.h"
#import "AFNetworking.h"
#import "FiveColumnsESRootClass.h"
#import "FiveColumnsCategories.h"
#import "FiveColumnsIphone.h"
#import "FiveColumnsMagazine.h"



#import "Newspageesarray.h"
#import "Columnpageesarray.h"
#import "Depthpageesarray.h"
#import "Activeesarray.h"
#import "Viewpointesarray.h"
#import "FiveColumnsTwoDetailViewController.h"



@interface ColumnsViewController ()<UITableViewDataSource,UITableViewDelegate>
//tableview属性
@property (nonatomic,strong) UITableView *fiveColumnsTableView;

@property (nonatomic,strong) FiveColumnsESRootClass *fiveColumnsESRootClass;


//新闻页数组
@property (nonatomic,strong) NSMutableArray<Newspageesarray *> *newspageesArray;
//专栏页数组
@property (nonatomic,strong) NSMutableArray<Columnpageesarray *> *ColumnpageesArray;
//深度页数组
@property (nonatomic,strong) NSMutableArray<Depthpageesarray *> *DepthpageesArray;
//活动页数组
@property (nonatomic,strong) NSMutableArray<Activeesarray *> *ActiveesArray;
//观点页数组
@property (nonatomic,strong) NSMutableArray<Viewpointesarray *> *ViewpointesArray;
@end

@implementation ColumnsViewController

#pragma mark ----视图加载
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createfiveColumnsTableView];
}


    
    


- (void)createfiveColumnsTableView
{
    _fiveColumnsTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    _fiveColumnsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _fiveColumnsTableView.delegate = self;
    _fiveColumnsTableView.dataSource = self;
    
    [self.view addSubview:_fiveColumnsTableView];
    [_fiveColumnsTableView registerClass:[FiveColumnsTableViewCell class] forCellReuseIdentifier:@"fiveColumnsTableViewCell"];
    
    [self.fiveColumnsTableView reloadData];
    
    [self columnsnetworkGet];
}

#pragma mark ----column网络请求
- (void)columnsnetworkGet
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *requestURLString = @"http://watch-cdn.idailywatch.com/app/watch/category/iphone?ver=iphone&app_ver=15";
    
    manager.requestSerializer = [AFJSONRequestSerializer serializer];

    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    [manager GET:requestURLString parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSDictionary dictionary];
        dic = responseObject;
        _fiveColumnsESRootClass = [FiveColumnsESRootClass modelWithDic:dic];
        NSLog(@"11111111111111%@",_fiveColumnsESRootClass.categories);
//        NSLog(@"333333%@",_fiveColumnsESRootClass);
        [self.fiveColumnsTableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",task.currentRequest);
        NSLog(@"请求失败%@",error);
    }];
    
    
}




#pragma mark -----column的tableview返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    FiveColumnsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fiveColumnsTableViewCell"];

    cell.titleLabel.text = _fiveColumnsESRootClass.categories.magazine[indexPath.row + 1].title;
    cell.nameLabel.text = _fiveColumnsESRootClass.categories.magazine[indexPath.row + 1].name;
    cell.totalLabel.text = [NSString stringWithFormat:@"%ld",_fiveColumnsESRootClass.categories.magazine[indexPath.row + 1].total];
    return cell;
}
#pragma mark ----item的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}


#pragma mark -----tableview的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}

#pragma mark ----tableviewcell的点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    FiveColumnsDetailViewController *fiveDetailVC = [FiveColumnsDetailViewController new];
    [self.navigationController pushViewController:fiveDetailVC animated:YES];
    NSInteger row = [indexPath row];
    fiveDetailVC.rowValue = row;
    FiveColumnsTwoDetailViewController *fiveTwoVC = [FiveColumnsTwoDetailViewController new];
    fiveTwoVC.row = row;
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
